﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://monengine4net.4thex.com/XMLSchema" xmlns:m="http://monengine4net.4thex.com/XMLSchema">
  <xs:complexType name="Transaction">
    <xs:sequence>
      <xs:element name="description" type="xs:string" minOccurs="0" />
      <xs:element name="action" maxOccurs="unbounded" minOccurs="2" type="m:Action" />
    </xs:sequence>
    <xs:attribute name="timestamp" type="xs:dateTime" />
  </xs:complexType>
  <xs:simpleType name="AccountType">
    <xs:annotation>
      <xs:documentation>Type of account</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="ASSET">
        <xs:annotation>
          <xs:documentation>Asset account</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="LIABILITY">
        <xs:annotation>
          <xs:documentation>Liability account</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="INCOME">
        <xs:annotation>
          <xs:documentation>Income account</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="EXPENSE">
        <xs:annotation>
          <xs:documentation>Expense account</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="ContactType">
    <xs:sequence>
      <xs:element name="email" type="xs:string" maxOccurs="1" minOccurs="0" />
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" />
  </xs:complexType>

  <xs:element name="system">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="accounts" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" minOccurs="0" name="account">
                <xs:complexType>
                  <xs:attribute name="number" type="xs:nonNegativeInteger" use="required" />
                  <xs:attribute name="type" type="m:AccountType" use="required" />
                  <xs:attribute name="name" type="xs:string" use="required" />
                  <xs:attribute name="description" type="xs:string" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="transactions" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="transaction" maxOccurs="unbounded" minOccurs="0" type="m:Transaction" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="contacts" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="contact" maxOccurs="unbounded" minOccurs="0" type="m:ContactType" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:complexType name="Action">
    <xs:sequence>
    </xs:sequence>
    <xs:attribute name="type" type="m:ActionType" />
    <xs:attribute name="amount" type="xs:decimal" />
    <xs:attribute name="account" type="xs:nonNegativeInteger" />
  </xs:complexType>
  <xs:simpleType name="ActionType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="DEBIT" />
      <xs:enumeration value="CREDIT" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>